package com.example.boot3.service.Impl;

import com.example.boot3.mapper.DriverMapper;
import com.example.boot3.model.Driver;
import com.example.boot3.service.DriverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author 邹成明
 */
@Service
public class DriverServiceImpl implements DriverService {

    @Autowired
    private DriverMapper driverMapper;
    @Override
    public List<Driver> getDriversInfoList() {
        return driverMapper.getDriversInfoList();
    }

    @Override
    public List<Map<String, String>> getDriversCountByStatus() {
        return driverMapper.getDriversCountByStatus();
    }

    @Override
    public Integer addDriver(Driver driver) {
        try {
            driverMapper.addDriver(driver);
            return 1;
        } catch (DuplicateKeyException e) {
            // 捕获唯一键约束冲突的异常
            return 0;

        }

    }
}
